import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.Border;
 
public class playerpanel extends JPanel{

	
 	private JLabel cash1, cash2, cash3, cash4;
 	private int p1cash, p2cash, p3cash, p4cash;
 	private JLabel total1, total2, total3, total4;
 	private int p1totalWorth, p2totalWorth, p3totalWorth, p4totalWorth;
 	private JLabel player1, player2, player3, player4;
 	private String p1name, p2name, p3name, p4name;
 	private JLabel player1total, player2total, player3total, player4total;
 	private JLabel player1cash, player2cash, player3cash, player4cash;
 	private JButton details1button, details2button, details3button, details4button;
 	
 	Icon greencash =new ImageIcon(getClass().getResource("./playerpanelimages/greencash.png"));
 	Icon bluecash =new ImageIcon(getClass().getResource("./playerpanelimages/bluecash.png"));
 	Icon yellowcash =new ImageIcon(getClass().getResource("./playerpanelimages/yellowcash.png"));
 	Icon redcash =new ImageIcon(getClass().getResource("./playerpanelimages/redcash.png"));
 	
 	Icon worth =new ImageIcon(getClass().getResource("./playerpanelimages/worth.png"));
 	Icon redworth =new ImageIcon(getClass().getResource("./playerpanelimages/redworth.png"));
 	Icon yellowworth =new ImageIcon(getClass().getResource("./playerpanelimages/yellowworth.png"));
 	Icon blueworth =new ImageIcon(getClass().getResource("./playerpanelimages/blueworth.png"));
 	
 	Icon bluedetails =new ImageIcon(getClass().getResource("./playerpanelimages/bluedetails.png"));
 	Icon reddetails =new ImageIcon(getClass().getResource("./playerpanelimages/reddetails.png"));
 	Icon greendetails =new ImageIcon(getClass().getResource("./playerpanelimages/greendetails.png"));
 	Icon yellowdetails =new ImageIcon(getClass().getResource("./playerpanelimages/yellowdetails.png"));
 	
/*
 	Icon greencash =new ImageIcon("./playerpanelimages/greencash.png"));
 	Icon bluecash =new ImageIcon("./playerpanelimages/bluecash.png"));
 	Icon yellowcash =new ImageIcon("./playerpanelimages/yellowcash.png"));
 	Icon redcash =new ImageIcon("./playerpanelimages/redcash.png"));
 	
 	Icon worth =new ImageIcon("./playerpanelimages/worth.png"));
 	Icon redworth =new ImageIcon("./playerpanelimages/redworth.png"));
 	Icon yellowworth =new ImageIcon("./playerpanelimages/yellowworth.png"));
 	Icon blueworth =new ImageIcon("./playerpanelimages/blueworth.png"));
 	
 	Icon bluedetails =new ImageIcon("./playerpanelimages/bluedetails.png"));
 	Icon reddetails =new ImageIcon("./playerpanelimages/reddetails.png"));
 	Icon greendetails =new ImageIcon("./playerpanelimages/greendetails.png"));
 	Icon yellowdetails =new ImageIcon("./playerpanelimages/yellowdetails.png"));
 	*/
 	
 	private PlayerDetailsPanel pdp;
 	
 	private ArrayList<String> p1PropertiesOwned;
 	private ArrayList<String> p2PropertiesOwned;
 	private ArrayList<String> p3PropertiesOwned;
 	private ArrayList<String> p4PropertiesOwned;
 	
 	private ArrayList<String> p1JailFree;
 	private ArrayList<String> p2JailFree;
 	private ArrayList<String> p3JailFree;
 	private ArrayList<String> p4JailFree;
 	
 	private int p1propsnumber= 0;
 	private int p2propsnumber =0;
 	private int p3propsnumber= 0;
 	private int p4propsnumber=0;
 	
 
	public playerpanel()
	{
    	p1PropertiesOwned = new ArrayList<String>();  
    	p2PropertiesOwned = new ArrayList<String>(); 
    	p3PropertiesOwned = new ArrayList<String>(); 
    	p4PropertiesOwned = new ArrayList<String>(); 
    	
         	
    	p1JailFree = new ArrayList<String>();
    	p2JailFree = new ArrayList<String>();
    	p3JailFree = new ArrayList<String>();
    	p4JailFree = new ArrayList<String>();
    	
    	 /*
    	 
 addProperty("ParkPlace", 1);
	 addProperty("Boardwalk", 4);
	 addProperty("IndianaAve", 2);
   	 addProperty("B&Orailroad", 3);
	 addProperty("OrientalAve", 1);
	 addProperty("VermontAve", 1);
	 addProperty("IllinoisAve", 1);
	 addProperty("IndianaAve", 1);
	 addProperty("PennsylvaniaAve", 1);	 
	 addProperty("ReadingRailroad", 1);
	 addProperty("IndianaAve", 1); 
	 addProperty("IndianaAve", 3);
	 addProperty("PennsylvaniaAve", 2);	 
	 addProperty("ReadingRailroad", 2);
	 addProperty("IndianaAve", 3);
     addProperty("IndianaAve", 2);
	 addProperty("WaterWorks", 1);
	 addProperty("BalticAve", 4);
	 
	 
    	  
	 addProperty("BalticAve", 1);
	  
	 addProperty("ConnecticutAve", 1);
	 addProperty("VermontAve", 1);
	 addProperty("OrientalAve", 1);	 
	 addProperty("TennesseeAve", 1);
	 addProperty("VentnorAve", 1);
	 addProperty("MarvinGardens", 1);
	 addProperty("PennsylvaniaRailroad", 1);
	 addProperty("PacificAve", 1);
	 addProperty("NorthCarolinaAve", 1);
	 addProperty("PennsylvaniaAve", 1);
	 addProperty("ParkPlace", 1);
	 addProperty("Boardwalk", 1);
	 addProperty("StCharlesPlace", 1);
	 addProperty("StatesAve", 1);
	 addProperty("VirginiaAve", 1);
	 addProperty("StJamesPlace", 1);	 
	 addProperty("NewYorkAve", 1);
	 addProperty("KentuckyAve", 1);
	 addProperty("IndianaAve", 1);
	 addProperty("IllinoisAve", 1);
	 addProperty("AtlanticAve", 1);	  
	 addProperty("ReadingRailroad", 1);
	 addProperty("B&ORailroad", 1);
	 addProperty("ShortLineRailroad", 1);	 
	 addProperty("ElectricCompany", 1);
	 addProperty("MediterraneanAve", 1);	
	 addProperty("WaterWorks", 1);
	 
	 
	 addJailFreeCard("jailfreechance",1);
	 addJailFreeCard("jailfreechest",1);
	
	*/	
		
		
		Border etchedBdr = BorderFactory.createEtchedBorder();
		setLayout(new GridBagLayout());	
		setPreferredSize(new Dimension(200, 400));
		setBackground (new Color(200,222,186));
		
		setBorder(etchedBdr);
	
		
		cash1 = new JLabel(redcash);
		cash2 = new JLabel(bluecash);
		cash3 = new JLabel(greencash);
		cash4 = new JLabel(yellowcash);
			
		total1 = new JLabel(redworth);
		total2 = new JLabel(blueworth);
		total3 = new JLabel(worth);
		total4 = new JLabel(yellowworth);
		
		player1  = new JLabel("Player 1");
		player2  = new JLabel("Player 2");
		player3  = new JLabel("Player 3");
		player4  = new JLabel("Player 4");
		
		
 
	 
 
	
		player1cash  = new JLabel("$ 1500");
		player2cash  = new JLabel("$ 1500");
		player3cash  =new JLabel("$ 1500");
		player4cash  = new JLabel("$ 1500");
		
		player1cash.setFont(new Font("Serif", Font.BOLD, 20));
		player2cash.setFont(new Font("Serif", Font.BOLD, 20));
		player3cash.setFont(new Font("Serif", Font.BOLD, 20));
		player4cash.setFont(new Font("Serif", Font.BOLD, 20));
		
		player1total  = new JLabel("$ 1500");
		player2total  = new JLabel("$ 1500");
		player3total  = new JLabel("$ 1500");
		player4total  = new JLabel("$ 1500");
		
		player1total.setFont(new Font("Serif", Font.BOLD, 20));
		player2total.setFont(new Font("Serif", Font.BOLD, 20));
		player3total.setFont(new Font("Serif", Font.BOLD, 20));
		player4total.setFont(new Font("Serif", Font.BOLD, 20));
		
		details1button = new JButton(reddetails);
		details2button = new JButton(bluedetails);
		details3button = new JButton(greendetails);
		details4button = new JButton(yellowdetails);
		
		details1button.setBackground (new Color(200,222,186));
		details2button.setBackground (new Color(200,222,186));
		details3button.setBackground (new Color(200,222,186));
		details4button.setBackground (new Color(200,222,186));
		
	 

		details1button.setBorderPainted(false);
		details2button.setBorderPainted(false);
		details3button.setBorderPainted(false);
		details4button.setBorderPainted(false);
		
		player1.setForeground(Color.red);
		player2.setForeground(Color.BLUE);
		player3.setForeground(Color.green);
		player4.setForeground(Color.yellow);
		
		player1.setFont(new Font("impact", Font.PLAIN, 20));
		player2.setFont(new Font("IMPACT", Font.PLAIN, 20));
		player3.setFont(new Font("IMPACT", Font.PLAIN, 20));
		player4.setFont(new Font("IMPACT", Font.PLAIN, 20)); 
		
		player1cash.setForeground(Color.red);
		player2cash.setForeground(Color.blue);
		player3cash.setForeground(Color.green);
		player4cash.setForeground(Color.yellow);
		
		player1cash.setForeground(Color.red);
		player2cash.setForeground(Color.blue);
		player3cash.setForeground(Color.green);
		player4cash.setForeground(Color.yellow);
		
		player1total.setForeground(Color.red);
		player2total.setForeground(Color.blue);
		player3total.setForeground(Color.green);
		player4total.setForeground(Color.yellow);
		
 
				 
		 GridBagConstraints con = new GridBagConstraints();
		  	    
 
		 con.insets = new Insets(0,20,0,0);
		 
 //player1 info
        con.gridx =0;
		con.gridy =1;
		add(player1, con);
		
		con.gridx =1;
		con.gridy =1;
		add(details1button, con);
		
		con.gridx =0;
		con.gridy =2;
		add(cash1, con);
		
		con.gridx =1;
		con.gridy =2;
		add(player1cash, con);
		
		con.gridx =0;
		con.gridy =3;
		add(total1, con);
		
		con.gridx =1;
		con.gridy =3;
		add(player1total, con);
		
 
//player 2 info		
        con.gridx =0;
		con.gridy =4;
		add(player2, con);
		
		con.gridx =1;
		con.gridy =4;
		add(details2button, con);
		
		con.gridx =0;
		con.gridy =5;
		add(cash2, con);
		
		con.gridx =1;
		con.gridy =5;
		add(player2cash, con);
		
		con.gridx =0;
		con.gridy =6;
		add(total2, con);
		
		con.gridx =1;
		con.gridy =6;
		add(player2total, con);	
		
//player 3 info		

		
		con.gridx =0;
		con.gridy =7;
		add(player3, con);
		
		con.gridx =1;
		con.gridy =7;
		add(details3button, con);
		
		con.gridx =0;
		con.gridy =8;
		add(cash3, con);
		
		con.gridx =1;
		con.gridy =8;
		add(player3cash, con);
		
		con.gridx =0;
		con.gridy =9;
		add(total3, con);
		
		con.gridx =1;
		con.gridy =9;
		add(player3total, con);	
		
//player 4 info		

		con.gridx =0;
		con.gridy =10;
		add(player4, con);
		
		con.gridx =1;
		con.gridy =10;
		add(details4button, con);
		
		con.gridx =0;
		con.gridy =11;
		add(cash4, con);
		
		con.gridx =1;
		con.gridy =11;
		add(player4cash, con);
		
		con.gridx =0;
		con.gridy =12;
		add(total4, con);
		
		con.gridx =1;
		con.gridy =12;
		add(player4total, con);
		
 
	    HandlerClass1 player1handler = new HandlerClass1();
		HandlerClass2 player2handler = new HandlerClass2();
		HandlerClass3 player3handler = new HandlerClass3();
		HandlerClass4 player4handler = new HandlerClass4();
		
		details1button.addActionListener(player1handler);
		details2button.addActionListener(player2handler);
		details3button.addActionListener(player3handler);
		details4button.addActionListener(player4handler);
	 
	}
	
	public void setPlayerName(String name, int playerNum)
	{
		if(playerNum == 1)
		{	
			player1.setText(name);
			p1name = name;
		}
		else if(playerNum == 2)
		{
			player2.setText(name);
			p2name = name;
		}
		else if(playerNum == 3)
		{
			player3.setText(name);
			p3name = name;
		}
		else if(playerNum == 4)
		{
			player4.setText(name);
			p4name = name;
		}
	}
	
	public void setCashValue(int value, int playerNum)
	{
		if(playerNum == 1)
		{
			player1cash.setText("$ " + value);
			p1cash = value;
		}
		else if(playerNum == 2)
		{
			player2cash.setText("$" + value);
			p2cash = value;
		}
		else if(playerNum == 3)
		{
			player3cash.setText("$ " + value);
			p3cash = value;
		}
		else if(playerNum == 4)
		{
			player4cash.setText("$ " + value);
			p4cash = value;
		}
	}
	
	public void setTotalWorth(int value, int playerNum)
	{
		if(playerNum == 1)
		{
			player1total.setText("$ " + value);
			p1totalWorth = value;
		}
		else if(playerNum == 2)
		{
			player2total.setText("$" + value);
			p2totalWorth = value;
		}
		else if(playerNum == 3)
		{
			player3total.setText("$ " + value);
			p3totalWorth = value;
		}
		else if(playerNum == 4)
		{
			player4total.setText("$ " + value);
			p4totalWorth = value;
		}
		
		
	}
	
 public void addProperty(String Name, int playerNum)
 {
	 if(playerNum == 1)
		{
		 p1PropertiesOwned.add(Name);
		 
		 p1propsnumber++;
		}
	 if(playerNum == 2)
		{
		 p2PropertiesOwned.add(Name);
		 p2propsnumber++;
		 
		}
	 if(playerNum == 3)
		{
		 p3PropertiesOwned.add(Name);
		 p3propsnumber++;
		 
		}
	 if(playerNum == 4)
		{
		 p4PropertiesOwned.add(Name);
		 p4propsnumber++;
		 
		}
	 
	 
 }
 
 
 
 public void removeProperty(String Name, int playerNum)
 {
	 if(playerNum == 1)
		{
		 p1PropertiesOwned.remove(Name);
		 
		 p1propsnumber--;
		}
	 if(playerNum == 2)
		{
		 p2PropertiesOwned.remove(Name);
		 p2propsnumber--;
		 
		}
	 if(playerNum == 3)
		{
		 p3PropertiesOwned.remove(Name);
		 p3propsnumber--;
		 
		}
	 if(playerNum == 4)
		{
		 p4PropertiesOwned.remove(Name);
		 p4propsnumber--;
		 
		}
	 
	 
 }
	
 public void addJailFreeCard(String Name, int playerNum)
 {
	 if(playerNum == 1)
		{
		 p1JailFree.add(Name);
		 
	 
		}
	 if(playerNum == 2)
		{
		 p2JailFree.add(Name);
	 
		 
		}
	 if(playerNum == 3)
		{
		 p3JailFree.add(Name);
		  
		 
		}
	 if(playerNum == 4)
		{
		 p4JailFree.add(Name);
		 
		 
		}
	 
	 
 }
 
 public void removeJailFreeCard(String Name, int playerNum)
 {
	 if(playerNum == 1)
		{
		 p1JailFree.remove(Name);
		 
	 System.out.println(p1JailFree);
		}
	 if(playerNum == 2)
		{
		 p2JailFree.remove(Name);
	 
		 
		}
	 if(playerNum == 3)
		{
		 p3JailFree.remove(Name);
		  
		 
		}
	 if(playerNum == 4)
		{
		 p4JailFree.remove(Name);
		 
		 
		}
	 
	 
 }
 
 private class HandlerClass1 implements ActionListener
	{		
		
		public void actionPerformed (ActionEvent event)
		{
			
			pdp = new PlayerDetailsPanel(p1name, p1cash, p1totalWorth, p1propsnumber, p1PropertiesOwned, p1JailFree);
			JFrame frame = new JFrame ("Player 1 Details");
			
			// Don't need to EXIT_ON_CLOSE or else it will kill the whole
			// program.  Just X'ing out the frame will close it
			frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
			
			// add the PlayerDetailsPanel to the frame
			frame.getContentPane().add(pdp);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.setResizable(true);
			frame.setVisible(true);
			
		}

	}

	private class HandlerClass2 implements ActionListener{		
		
		public void actionPerformed (ActionEvent event)
		{
			
			pdp = new PlayerDetailsPanel(p2name, p2cash, p2totalWorth, p2propsnumber, p2PropertiesOwned, p2JailFree);
			JFrame frame = new JFrame ("Player 2 Details");
			
			// Don't need to EXIT_ON_CLOSE or else it will kill the whole
			// program.  Just X'ing out the frame will close it
			frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
			
			// add the PlayerDetailsPanel to the frame
			frame.getContentPane().add(pdp);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.setResizable(true);
			frame.setVisible(true);
			
		}
	}		
	private class HandlerClass3 implements ActionListener{		
		
		public void actionPerformed (ActionEvent event)
		{
			
			pdp = new PlayerDetailsPanel(p3name, p3cash, p3totalWorth, p3propsnumber, p3PropertiesOwned, p3JailFree);
			JFrame frame = new JFrame ("Player 3 Details");
			
			// Don't need to EXIT_ON_CLOSE or else it will kill the whole
			// program.  Just X'ing out the frame will close it
			frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
			
			// add the PlayerDetailsPanel to the frame
			frame.getContentPane().add(pdp);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.setResizable(true);
			frame.setVisible(true);
			
		}
	}
	private class HandlerClass4 implements ActionListener{		
		
		public void actionPerformed (ActionEvent event)
		{
			
			pdp = new PlayerDetailsPanel(p4name, p4cash, p4totalWorth, p4propsnumber, p4PropertiesOwned,p4JailFree );
			JFrame frame = new JFrame ("Player 4 Details");
			
			// Don't need to EXIT_ON_CLOSE or else it will kill the whole
			// program.  Just X'ing out the frame will close it
			frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
			
			// add the PlayerDetailsPanel to the frame
			frame.getContentPane().add(pdp);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.setResizable(true);
			frame.setVisible(true);
			
		}
	}

 
}